
from pluginHelper import *
import re

ro = re.compile(r"^\s*#if \d+.*?#endif", re.MULTILINE| re.DOTALL)

SEVERITY = 1

#
# This is a scanner function that can scan the file line-by-line.
# The function is called once for each line in the input file. THe filename
# and current line number is passed to the function. The function returns
# a boolean value indicating whether it wants more input (True), or whether
# it does not care any moer about this file (False).
#
# errors are reported using reportError(line, col)
#
def scanFile(self, file):
	data = file.read()
	so = ro.search(data)
	while so:
		start = so.start()
		end = so.end()

		lineStart = len(data[:start].split('\n'))
		lineEnd = len(data[:end].split('\n'))

		reportError(lineStart, 0, lineEnd - lineStart + 1, SEVERITY)

		so = ro.search(data, end)
	#
	# Assume that each loop starts on a new line:
	return True


#
# Describe the plugin:
if __name__ == "__main__":
	init()
	describePlugin('hashifzero','scanner', 'Checks for blocks of code that have been commented out or enabled using the "#if N" construct.')

	#
	# Set the scan function, along with it's type:
	setScanFunction(SCANNER_TYPE_FILE_OBJECT, scanFile)


